Public or shared assembly used by multiple application, if more than one application use assembly than that assembly must be add or copy to single location known as Global Assembly Cache (GAC). For calling assemblies within same application the same copy of shared assembly is used from original location. Shared assembly contains four part name including face name, version, public key token and cultural information. Public key token and version information makes impossible for two different assembly with same name or same assembly with different version to mix with each other.
Another definition for shared assembly
A shared assembly can also be defined as an assembly that placed in a common location known as the GAC (Global Assembly Cache) and that provides resources to the application. If an assembly is shared then it doesn’t mean that multiple copies will be created even when it is used by multiple applications. The GAC folder is contained under the Windows folder.
<drive>:\windows\assembly <GAC folder>
All base class libraries lie under GAC.
A strong named assembly is given into the GAC.
GAC is identified by public key token.
Generating a public key token:
we use command prompt by using strong named util tool which is command line tool.
Sn -k <file name>
E.g.:<drive>:\<folder> > sn -k key.snk
This above statement generates a key value and write it into "key.snk" file.
sn or snk used above is the extension of key file.
How to Create A shared assembly
Step 1: First Generate a key file.
<drive>:\<folder> sn -k key.snk
Step 2: now create a new project and attached key file to it before compilation so that a strong named assembly will be generated.
create a new project of type class and name it sAssembly;
Public string SayHello()
{
Return "hello to shared assembly";
}
To attached a key file we generate with the project, now open the project properties and select "signing" tab on the LHS that displays a CheckBox as "sign the assembly" select this which will displays ComboBox below it from that open browse and select key.snk from the physical location and then compile the project by using build which will generate assembly file called as Assembly.dll which is strong named.
Step 3: the third step is to copy the assembly into GAC.
Add reference of a Assembly.dll file to open new project and write the code for the button click event.
sAssembly.Classs1 obj=new sAssembly.Class1();
Messagebox.Show(obj.SayHello());
At last run the project and verify under the current project of bin/debug folder, as Assembly.dll is shared assembly we cannot find it into the folder.
Liked By
Write Answer
What Is Shared Assembly ?
Join MindStick Community
You have need login or register for voting of answers or question.
Nishi Tiwari
13-Dec-2019Public or shared assembly used by multiple application, if more than one application use assembly than that assembly must be add or copy to single location known as Global Assembly Cache (GAC). For calling assemblies within same application the same copy of shared assembly is used from original location. Shared assembly contains four part name including face name, version, public key token and cultural information. Public key token and version information makes impossible for two different assembly with same name or same assembly with different version to mix with each other.
Another definition for shared assembly
A shared assembly can also be defined as an assembly that placed in a common location known as the GAC (Global Assembly Cache) and that provides resources to the application. If an assembly is shared then it doesn’t mean that multiple copies will be created even when it is used by multiple applications. The GAC folder is contained under the Windows folder.
<drive>:\windows\assembly <GAC folder>
All base class libraries lie under GAC.
A strong named assembly is given into the GAC.
GAC is identified by public key token.
Generating a public key token:
we use command prompt by using strong named util tool which is command line tool.
Sn -k <file name>
E.g.:<drive>:\<folder> > sn -k key.snk
This above statement generates a key value and write it into "key.snk" file.
sn or snk used above is the extension of key file.
How to Create A shared assembly
Step 1: First Generate a key file.
<drive>:\<folder> sn -k key.snk
Step 2: now create a new project and attached key file to it before compilation so that a strong named assembly will be generated.
create a new project of type class and name it sAssembly;
Public string SayHello()
{
Return "hello to shared assembly";
}
To attached a key file we generate with the project, now open the project properties and select "signing" tab on the LHS that displays a CheckBox as "sign the assembly" select this which will displays ComboBox below it from that open browse and select key.snk from the physical location and then compile the project by using build which will generate assembly file called as Assembly.dll which is strong named.
Step 3: the third step is to copy the assembly into GAC.
Gacutil -I | -u <assembly name> I:install u:uninstall
now, open a VS command prompt;and went to that location where Assembly.dll file is present and the following code
<drive>:\<folder>\sAssembly\ sAssembly\\bin\Debug>gacutil -I Assembly.dll
Step 4: Testing
Add reference of a Assembly.dll file to open new project and write the code for the button click event.
sAssembly.Classs1 obj=new sAssembly.Class1();
Messagebox.Show(obj.SayHello());
At last run the project and verify under the current project of bin/debug folder, as Assembly.dll is shared assembly we cannot find it into the folder.